import * as http from '@api/http'

/**
 * @purpose 获取用户信息
 * @returns {PromiseLike<T> | Promise<T> | *}
 */
export function info () {
  return http
    .get('member.info')
    .then(r => r.data)
}

/**
 * @purpose 设置昵称
 * @param nickname
 * @returns {Promise<T>}
 */
export function setNickname (nickname) {
  return http
    .post('member.setNickname', {
      nickname: nickname
    })
    .then(r => r.data)
}

/**
 * @purpose 设置用户名
 * @param username
 * @returns {Promise<T>}
 */
export function setUsername (username) {
  return http
    .post('member.setUsername', {
      username: username
    })
    .then(r => r.data)
}
/**
 * @purpose 设置密码
 * @param password
 * @returns {Promise<T>}
 */
export function setPassword (password) {
  return http
    .post('member.setPassword', {
      password: password
    })
    .then(r => r.data)
}
/**
 * @purpose 设置密码
 * @param oldPassword
 * @param newPassword
 * @returns {Promise<T>}
 */
export function editPassword (oldPassword, newPassword) {
  return http
    .post('member.editPassword', {
      old_password: oldPassword,
      new_password: newPassword
    })
    .then(r => r.data)
}

/**
 * @purpose 绑定手机号码
 * @param mobile
 * @param code
 * @returns {AxiosPromise<any> | void | *}
 */
export function bindMobile (mobile, code) {
  return http
    .post('member.bindMobile', {
      mobile: mobile,
      code: code
    })
    .then(r => r.data)
}

/**
 * @purpose 用户登录之后获取验证码
 * @returns {PromiseLike<T> | Promise<T> | *}
 */
export function getCode () {
  return http
    .get('member.getCode')
    .then(r => r.data)
}

/**
 * @purpose 更换手机号码
 * @param oldMobile
 * @param oldCode
 * @param newMobile
 * @param newCode
 * @returns {Promise<T>}
 */
export function changeMobile (
  oldMobile = '',
  oldCode = '',
  newMobile = '',
  newCode = ''
) {
  return http
    .post('member.changeMobile', {
      old_mobile: oldMobile,
      old_code: oldCode,
      new_mobile: newMobile,
      new_code: newCode
    })
    .then(r => r.data)
}
